<?php
require_once('../../_libs/mysql.php');
include('../../_libs/Classes/web/main.class.php');
include('../../_libs/Classes/login/user.class.php');
$user = new user;
/*
 * Get Shoutbox Entrys
 */
$sql = 'SELECT id, userID, message, timestamp FROM ' . DB_CMS . '.module_shoutbox ORDER BY id DESC LIMIT 5';
$dbh = $connection->prepare($sql);
$dbh->execute();
$i = 0;
foreach ($dbh->fetchAll(PDO::FETCH_ASSOC) AS $row) {
	$value[] = $row;
	$i++;
	?>
	<div style="font-size:10px;"><strong><a href="index.php?mod=profile&userID=<?php echo $row['userID']; ?>" target="_blank"><?php echo $user->getName($row['userID']); ?></a> - <?php echo $row['timestamp']; ?></strong></div>
	<div class="message"><?php echo $row['message']; ?></div><br />
	<?php
}
if (isset($_POST['message'])) {
	$main = new main;

	$sql = 'INSERT INTO ' . DB_CMS . '.module_shoutbox (userID, message, timestamp) VALUES (:userID, :message, CURRENT_TIMESTAMP)';
	$dbh = $connection->prepare($sql);
	$dbh->bindValue(':userID', $_SESSION['id']);
	$dbh->bindValue(':message', $_POST['message']);
	$dbh->execute();
	$main->logAction($_SESSION['id'], 'shoutbox_log', 2);
}
?>
